﻿using MachineVision.API.Models;
using MachineVision.Service;
using MachineVision.Service.Dto;
using Microsoft.AspNetCore.Mvc;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace MachineVision.API.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class TemperatureController : ControllerBase
    {
        private readonly ILogger<WeatherForecastController> _logger;
        private readonly ITemperatureService _tService;
        public TemperatureController(ILogger<WeatherForecastController> logger, ITemperatureService tService)
        {
            _logger = logger;
            _tService = tService;
        }

        // GET: api/<TemperatureController>
        [HttpGet]
        public ApiResult Get(int pageNum = 1, int pageSize = 20, DateTime? TimeBegin = null,DateTime? TimeEnd=null)
        {
            ApiResult result = new ApiResult();
            result.data = _tService.GetDatas(pageNum, pageSize, TimeBegin, TimeEnd);
            return result;
        }

        [Route("GetDay")]
        [HttpGet]
        public ApiResult GetDay(DateTime time,int pageNum = 1, int pageSize = 20)
        {
            ApiResult result = new ApiResult();
            result.data = _tService.GetDayDatas(pageNum, pageSize, time);
            return result;
        }

        [Route("Get24")]
        [HttpGet]
        public ApiResult Get24(DateTime time, int pageSize = 64)
        {
            ApiResult result = new ApiResult();
            //var Now = DateTime.Now;
            result.data = _tService.Get24Datas(time,pageSize);
            return result;
        }

        // GET api/<TemperatureController>/5
        [HttpGet("{id}")]
        public ApiResult Get(int id)
        {
            //throw new KeyNotFoundException("Get User failed");
            ApiResult result = new ApiResult();
            result.data = _tService.GetData(id);
            return result;
        }

        // POST api/<TemperatureController>
        [HttpPost]
        public ApiResult Post([FromBody] TemperatureReq value)
        {
            ApiResult result = new ApiResult();
            result.data = _tService.AddData(value);
            return result;
        }

        // PUT api/<TemperatureController>/5
        [HttpPut("{id}")]
        public ApiResult Put(int id, [FromBody] TemperatureReq value)
        {
            ApiResult result = new ApiResult();
            result.data = _tService.ModifyData(id,value);
            return result;
        }

        //// DELETE api/<TemperatureController>/5
        //[HttpDelete("{id}")]
        //public void Delete(int id)
        //{
        //}
    }
}
